package com.zhang.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import java.time.LocalDate;

/**
 * 用户实体类
 */
@Data
@NoArgsConstructor
public class UserBean {
    /**用户id*/
    private int id;
    /**用户名*/
    @Pattern(regexp = "[\\u4e00-\\u9fa5a-zA-Z]{2,10}" , message = "用户名只能是2-10位字符字母")
    private String name;
    /**用户性别*/
    @Pattern(regexp = "[男]|[女]",message = "性别只能男或者女")
    private String sex;
    /**用户工资*/
    @Max(value = 10000,message = "工资给这么高老板会心痛的")
    @Min(value = 3000, message = "工资这么低员工会罢工的")
    private int money;
    /**用户生日*/
    @Pattern(regexp = "\\d{4}-\\d{2}-\\d{2}",message = "生日的格式只能是XXXX-XX-XX")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String birthday;

    public UserBean(String name, String sex, int money, LocalDate birthday) {
        this.name = name;
        this.sex = sex;
        this.money = money;
        this.birthday = birthday.toString();
    }

    @Override
    public String toString() {
        return "UserBean{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", money=" + money +
                ", birthday=" + birthday +
                '}' +"\n";
    }
}
